package com.ruoyi.edh.mapper;

import com.ruoyi.edh.domain.EdhShoppingCart;
import com.ruoyi.edh.domain.vo.EdhShoppingCartVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * 易订货-购物车Mapper接口
 * 
 * @author xxx
 * @date 2020-09-02
 */
public interface EdhShoppingCartMapper 
{
    /**
     * 查询易订货-购物车
     * 
     * @param id 易订货-购物车ID
     * @return 易订货-购物车
     */
    public EdhShoppingCartVo selectEdhShoppingCartById(Long id);

    /**
     * 查询易订货-购物车列表
     * 
     * @param edhShoppingCart 易订货-购物车
     * @return 易订货-购物车集合
     */
    public List<EdhShoppingCartVo> selectEdhShoppingCartList(EdhShoppingCart edhShoppingCart);

    /**
     * 新增易订货-购物车
     * 
     * @param edhShoppingCart 易订货-购物车
     * @return 结果
     */
    public int insertEdhShoppingCart(EdhShoppingCart edhShoppingCart);

    /**
     * 修改易订货-购物车
     * 
     * @param edhShoppingCart 易订货-购物车
     * @return 结果
     */
    public int updateEdhShoppingCart(EdhShoppingCart edhShoppingCart);

    /**
     * 删除易订货-购物车
     * 
     * @param id 易订货-购物车ID
     * @return 结果
     */
    public int deleteEdhShoppingCartById(Long id);

    /**
     * 根据用户id和商品id 删除购物车
     */
    public Integer deleteByUserIdAndGoodsId(@Param("userId") Long userId ,@Param("goodsIds") List<Long> goodsIds);

    /**
     * 批量删除易订货-购物车
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteEdhShoppingCartByIds(@Param("ids") String[] ids);

    /***************************************************************************************/
    /**
     * 使店铺id和商品id对应的购物车处于失效状态
     */
    @Select("update edh_shopping_cart set status = 1 where microshop_id = #{shopId} and goods_specifications_id in (select id from edh_goods_specifications where goods_id =#{goodsId})")
    public Integer killGoodsBymircoGoodsId(@Param("shopId") Object shopId , @Param("goodsId") Object goodsId);
    /**
     * 使店铺id和商品id对应的购物车处于失效状态
     */
    @Select("update edh_shopping_cart set status = 1 where  goods_specifications_id in (select id from edh_goods_specifications where goods_id =#{goodsId})")
    public Integer killGoodsByGoodsId(Long goodsId);

    @Update("update edh_shopping_address set sort = 0 where id = #{id}")
    Integer setDefaultAdress(@Param("id") Long id);
    @Update("update edh_shopping_address set sort = 1 where id != #{id} and create_by = #{userId}")
    Integer cancelDefaultAdress(@Param("id") Long id, @Param("userId") Long userId);
}
